﻿using System.Windows.Media;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void SetBlackBackAndWhiteForeground(bool withColorHeaderText = false)
        {
            if (Globals.selectedEditor == null) return;

            //现在添加了“黑底彩字”。
            //if (Globals.selectedEditor.DefaultBackground == Brushes.Black &&
            //    Globals.selectedEditor.DefaultForeground == Brushes.White) return;

            ModifingItem mi = new ModifingItem();

            Action actionBackground;

            if (Globals.selectedEditor.DefaultBackground is ImageBrush)
            {
                actionBackground = new Action(null, -1, null, null,
                    Globals.selectedEditor.DefaultBackgroundXmlString,
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultExBackgroundChanging, null);
            }
            else
            {
                actionBackground = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefaultBackground),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultExBackgroundChanging, null);
            }

            Globals.selectedEditor.DefaultBackground = Brushes.Black;

            Action actionForeground = new Action(null, -1, null, null,
                ColorPicker.GetBrushName(Globals.selectedEditor.DefaultForeground),
                ColorPicker.GetBrushName(Brushes.White),
                ActionType.DefaultExForegroundChanging, null);

            Globals.selectedEditor.DefaultForeground = Brushes.White;

            if (Globals.selectedEditor.SelectedExpression != null)
            {
                mi.OldSelectedExID = Globals.selectedEditor.SelectedExpression.ExID;
            }

            Action actionExSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.ExSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.GreenYellow), ActionType.ExSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.ExSelectionAdornerBrush = Brushes.GreenYellow;

            Action actionSubPanelSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.SubPanelSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.HotPink), ActionType.SubPanelSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.SubPanelSelectionAdornerBrush = Brushes.HotPink;

            if (withColorHeaderText)
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.Red), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.Red;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.Yellow), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.Yellow;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.Cyan), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.Cyan;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.DeepPink), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.DeepPink;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }
            else
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.White;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.White;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.White;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.White;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }

            Globals.selectedEditor.IsModified = true;

            mi.Add(actionBackground);
            mi.Add(actionForeground);
            mi.Add(actionExSelectionAdornerBrush);
            mi.Add(actionSubPanelSelectionAdornerBrush);

            Globals.selectedEditor.Do(mi);
        }

        public static void SetWhiteBackAndBlackForeground(bool withColorHeaderText = false)
        {
            if (Globals.selectedEditor == null) return;

            //现在添加了“白底彩字”。
            //if (Globals.selectedEditor.DefaultBackground == Brushes.White &&
            //    Globals.selectedEditor.DefaultForeground == Brushes.Black) return;

            ModifingItem mi = new ModifingItem();

            Action actionBackground;

            if (Globals.selectedEditor.DefaultBackground is ImageBrush)
            {
                actionBackground = new Action(null, -1, null, null,
                    Globals.selectedEditor.DefaultBackgroundXmlString,
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultExBackgroundChanging, null);
            }
            else
            {
                actionBackground = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefaultBackground),
                    ColorPicker.GetBrushName(Brushes.White), ActionType.DefaultExBackgroundChanging, null);
            }

            Globals.selectedEditor.DefaultBackground = Brushes.White;

            Action actionForeground = new Action(null, -1, null, null,
                ColorPicker.GetBrushName(Globals.selectedEditor.DefaultForeground),
                ColorPicker.GetBrushName(Brushes.Black),
                ActionType.DefaultExForegroundChanging, null);

            Globals.selectedEditor.DefaultForeground = Brushes.Black;

            if (Globals.selectedEditor.SelectedExpression != null)
            {
                mi.OldSelectedExID = Globals.selectedEditor.SelectedExpression.ExID;
            }

            Action actionExSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.ExSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.Brown), ActionType.ExSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.ExSelectionAdornerBrush = Brushes.Brown;

            Action actionSubPanelSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.SubPanelSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.Blue), ActionType.SubPanelSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.SubPanelSelectionAdornerBrush = Brushes.Blue;

            if (withColorHeaderText)
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.Red), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.Red;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.Fuchsia), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.Fuchsia;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.Blue), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.Blue;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.Green), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.Green;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }
            else
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.Black;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.Black;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.Black;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.Black;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }

            Globals.selectedEditor.IsModified = true;

            mi.Add(actionBackground);
            mi.Add(actionForeground);
            mi.Add(actionExSelectionAdornerBrush);
            mi.Add(actionSubPanelSelectionAdornerBrush);

            Globals.selectedEditor.Do(mi);
        }

        //透明色可以用来“露出”花纹背景。
        public static void SetTransparentBackAndBlackForeground(bool withColorHeaderText = false)
        {
            if (Globals.selectedEditor == null) return;

            //现在添加了“花纹底彩字”。
            //if (Globals.selectedEditor.DefaultBackground == Brushes.Transparent &&
            //    Globals.selectedEditor.DefaultForeground == Brushes.Black) return;

            ModifingItem mi = new ModifingItem();

            Action actionBackground;

            if (Globals.selectedEditor.DefaultBackground is ImageBrush)
            {
                actionBackground = new Action(null, -1, null, null,
                    Globals.selectedEditor.DefaultBackgroundXmlString,
                    ColorPicker.GetBrushName(Brushes.Transparent), ActionType.DefaultExBackgroundChanging, null);
            }
            else
            {
                actionBackground = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefaultBackground),
                    ColorPicker.GetBrushName(Brushes.Transparent), ActionType.DefaultExBackgroundChanging, null);
            }

            Globals.selectedEditor.DefaultBackground = Brushes.Transparent;

            Action actionForeground = new Action(null, -1, null, null,
                ColorPicker.GetBrushName(Globals.selectedEditor.DefaultForeground),
                ColorPicker.GetBrushName(Brushes.Black),
                ActionType.DefaultExForegroundChanging, null);

            Globals.selectedEditor.DefaultForeground = Brushes.Black;

            if (Globals.selectedEditor != null &&
                Globals.selectedEditor.SelectedExpression != null)
            {
                mi.OldSelectedExID = Globals.selectedEditor.SelectedExpression.ExID;
            }

            Action actionExSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.ExSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.Brown), ActionType.ExSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.ExSelectionAdornerBrush = Brushes.Brown;

            Action actionSubPanelSelectionAdornerBrush = new Action(null, -1, null, null,
               ColorPicker.GetBrushName(Globals.selectedEditor.SubPanelSelectionAdornerBrush),
               ColorPicker.GetBrushName(Brushes.Blue), ActionType.SubPanelSelectionAdornerBrushChanging, null);

            Globals.selectedEditor.SubPanelSelectionAdornerBrush = Brushes.Blue;

            if (withColorHeaderText)
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.Red), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.Red;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.Fuchsia), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.Fuchsia;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.Blue), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.Blue;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.Green), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.Green;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }
            else
            {
                Action actHeaderText1Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText1Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText1ColorChanging, null);

                Globals.selectedEditor.DefHeaderText1Brush = Brushes.Black;

                Action actHeaderText2Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText2Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText2ColorChanging, null);

                Globals.selectedEditor.DefHeaderText2Brush = Brushes.Black;

                Action actHeaderText3Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText3Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText3ColorChanging, null);

                Globals.selectedEditor.DefHeaderText3Brush = Brushes.Black;

                Action actHeaderText4Color = new Action(null, -1, null, null,
                    ColorPicker.GetBrushName(Globals.selectedEditor.DefHeaderText4Brush),
                    ColorPicker.GetBrushName(Brushes.Black), ActionType.DefaultHeaderText4ColorChanging, null);

                Globals.selectedEditor.DefHeaderText4Brush = Brushes.Black;

                mi.Add(actHeaderText1Color);
                mi.Add(actHeaderText2Color);
                mi.Add(actHeaderText3Color);
                mi.Add(actHeaderText4Color);
            }

            Globals.selectedEditor.IsModified = true;

            mi.Add(actionBackground);
            mi.Add(actionForeground);
            mi.Add(actionExSelectionAdornerBrush);
            mi.Add(actionSubPanelSelectionAdornerBrush);

            Globals.selectedEditor.Do(mi);
        }
    }
}
